﻿using BootstrapBlazor.Components;
using Microsoft.AspNetCore.SignalR;
using SubStationManagement.Server.Components;
using SubStationManagement.Server.Models;
using SubStationManagement.Server.Services;
using System.Text;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);

builder.Services.AddRazorComponents().AddInteractiveServerComponents();

builder.Services.AddBootstrapBlazor();

builder.Services.Configure<SubStationDatabaseSettings>(
    builder.Configuration.GetSection("SubStationDatabase"));

// 增加 Pdf 导出服务
builder.Services.AddBootstrapBlazorTableExportService();

// 增加 Html2Pdf 服务
builder.Services.AddBootstrapBlazorHtml2PdfService();

// 增加 SignalR 服务数据传输大小限制配置
builder.Services.Configure<HubOptions>(option => option.MaximumReceiveMessageSize = null);

builder.Services.AddSingleton(typeof(ILookupService), typeof(LookupService));
builder.Services.AddSingleton<MeasureModuleService>();
builder.Services.AddSingleton<TargetService>();
builder.Services.AddSingleton<RecordingModuleService>();
builder.Services.AddSingleton<DIDOModuleService>();
builder.Services.AddSingleton<MeasureSampleService>();
builder.Services.AddSingleton<HarmonicSampleService>();
builder.Services.AddSingleton<DIDOSampleService>();

var app = builder.Build();

if (!app.Environment.IsDevelopment())
{
    app.UseExceptionHandler("/Error");
}

app.UseAntiforgery();

app.MapStaticAssets();
app.MapRazorComponents<App>().AddInteractiveServerRenderMode();

app.Run();
